package calendar;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Scanner;

public class test2 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入年份");
        int year=sc.nextInt();
        System.out.println("请输入月份");
        int month=sc.nextInt();
        System.out.println("请输入日期");
        int day=sc.nextInt();

        Calendar calendar=Calendar.getInstance();
        calendar.set(year,month-1,day);

        // 获取日期
        int days = calendar.get(Calendar.DATE);
        // 获取当月的天数
        int ac = calendar.getActualMaximum(Calendar.DATE);
        // 设置日期为1号
        calendar.set(Calendar.DATE,1);
        // 获取1号为星期几
        int weeks = calendar.get(Calendar.DAY_OF_WEEK)-1;
        // 创建数组
        String[]  arr=new String[weeks+ac];

        for (int i=weeks;i<arr.length;i++){
            arr[i]=""+(i-weeks+1);
        }
        arr[day-1+weeks] = day+"*";
        String[] week = {"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
        Arrays.stream(week)
                .forEach(i-> System.out.print(i+"\t"));
        System.out.println();

        int count=7;

        for (int i=0;i<arr.length;i++){
            // 换行
            if (count <= 0) {
                count = 7;
                System.out.println();
            }
            count--;
            if (arr[i]==null){
                System.out.print("\t\t");
                continue;
            }
            System.out.print(arr[i]+"\t\t");
        }
    }
}
